package com.ssy.lingxi.common.constant.order;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 支付渠道 - 支付参数枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-08-10
 */
public enum OrderPaymentParameterEnum {
    UNKNOWN(0, "未知", "未知", Collections.singletonList(OrderPayChannelEnum.DOES_NOT_NEED)),

//    /**
//     * 支付宝 - 合作者身份Id - 1
//     */
//    ALIPAY_PARTNER_ID(1, "合作者身份Id", "partner_id", OrderPayChannelEnum.ALIPAY),

    /**
     * 支付宝 - AppId - 2
     */
    ALIPAY_APP_ID(2, "AppId", "app_id", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

//    /**
//     * 支付宝 - AesKey - 3
//     */
//    ALIPAY_AES_KEY(3, "AesKey", "aes_key", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

    /**
     * 支付宝 - RSA公钥 - 4
     */
    ALIPAY_PUBLIC_KEY(4, "RsaPublicKey", "rsa_public_key", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

//    /**
//     * 支付宝 - RSA私钥 - 5
//     */
//    ALIPAY_PRIVATE_KEY(5, "RsaPrivateKey", "rsa_private_key", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

//    /**
//     * 支付宝 - 前端页面通知地址 - 6
//     */
//    ALIPAY_RETURN_URL(6, "ReturnUrl", "return_url", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

    /**
     * 支付宝商户 - RSA私钥 - 7
     */
    APP_ALIPAY_PRIVATE_KEY(7, "RsaPrivateKey", "app_rsa_private_key", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

    /**
     * 支付宝第三方授权token - 8
     */
    ALIPAY_THREAD_APP_AUTH_TOKEN(8, "第三方授权Token", "app_auth_token", Collections.singletonList(OrderPayChannelEnum.ALIPAY)),

    /**
     * 微信 - 商户号 - 11
     */
    WECHAT_MERCHANT_ID(11, "商户号", "MchId", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信 - AppId - 12
     */
    WECHAT_APP_ID(12, "App Id", "AppId", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信 - Api密钥 - 13
     */
    WECHAT_API_KEY(13, "Api Key", "ApiKey", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信 - 商户证书 - 14
     */
    WECHAT_KEY_PATH(14, "商户证书", "KeyPath", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信 - 小程序开发者id - 15
     */
    WECHAT_APPLET_APP_ID(15, "小程序开发者id", "AppletAppId", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信 - 小程序开发者密钥 - 16
     */
    WECHAT_APPLET_APP_KEY(16, "小程序开发者密钥", "AppletAppKey", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信-公众号AppId - 17
     */
    WECHAT_PUBLIC_APP_ID(17,"微信公众号AppId","PublicAppId",Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 微信-公众号AppId - 18
     */
    WECHAT_PUBLIC_API_KEY(18,"微信公众号ApiKey","PublicApiKey",Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

//    /**
//     * 微信 - 开发者Id - 16
//     */
//    WECHAT_DEVELOPER_ID(16, "开发者Id", "develop_id", Collections.singletonList(OrderPayChannelEnum.WECHAT_PAY)),

    /**
     * 银联 - 商户号 - 20
     */
    UNION_MERCHANT_ID(20, "商户号", "mch_id", Collections.singletonList(OrderPayChannelEnum.UNION_PAY)),

    /**
     * 授信额度支付 - 初始申请额度 - 30
     */
    CREDIT_APPLY_AMOUNT(30, "初始申请额度", "初始申请额度不超过", Collections.singletonList(OrderPayChannelEnum.CREDIT)),

    /**
     * 授信额度支付 - 初始申请额度 - 31
     */
    CREDIT_DAYS(31, "调整周期", "天数", Collections.singletonList(OrderPayChannelEnum.CREDIT)),

    /**
     * 授信额度支付 - 上调比例 - 32
     */
    CREDIT_QUOTA_INCREAMENT(32, "上调百分比", "上调百分比", Collections.singletonList(OrderPayChannelEnum.CREDIT)),

    /**
     * 通联支付 - 所有支付方式通用 SysId - 40
     */
    ALLIN_SYS_ID(40, "通联支付SysId", "allin_sys_id", Stream.of(OrderPayChannelEnum.ALLIN_WECHAT, OrderPayChannelEnum.ALLIN_ALI_PAY, OrderPayChannelEnum.ALLIN_QUICK, OrderPayChannelEnum.ALLIN_UNION, OrderPayChannelEnum.ALLIN_BALANCE).collect(Collectors.toList())),

    /**
     * 通联支付 - 所有支付方式通用 私钥证书 - 41
     */
    ALLIN_PRIVATE_CERT_FILE(41, "通联支付私钥证书", "allin_private_cert", Stream.of(OrderPayChannelEnum.ALLIN_WECHAT, OrderPayChannelEnum.ALLIN_ALI_PAY, OrderPayChannelEnum.ALLIN_QUICK, OrderPayChannelEnum.ALLIN_UNION, OrderPayChannelEnum.ALLIN_BALANCE).collect(Collectors.toList())),

    /**
     * 通联支付 - 所有支付方式通用 私钥证书 - 42
     */
    ALLIN_PUBLIC_CERT_FILE(42, "通联支付公钥证书", "allin_public_cert", Stream.of(OrderPayChannelEnum.ALLIN_WECHAT, OrderPayChannelEnum.ALLIN_ALI_PAY, OrderPayChannelEnum.ALLIN_QUICK, OrderPayChannelEnum.ALLIN_UNION, OrderPayChannelEnum.ALLIN_BALANCE).collect(Collectors.toList())),

    /**
     * 通联支付 - 所有支付方式通用 标准账户集 - 43
     */
    ALLIN_STANDARD_SET(43, "通联支付标准账户集", "allin_standard_set", Stream.of(OrderPayChannelEnum.ALLIN_WECHAT, OrderPayChannelEnum.ALLIN_ALI_PAY, OrderPayChannelEnum.ALLIN_QUICK, OrderPayChannelEnum.ALLIN_UNION, OrderPayChannelEnum.ALLIN_BALANCE).collect(Collectors.toList())),

    /**
     * 通联支付 - 所有支付方式通用 标准账户集 - 44
     */
    ALLIN_DELEGATE_SET(44, "通联支付托管账户集", "allin_delegate_set", Stream.of(OrderPayChannelEnum.ALLIN_WECHAT, OrderPayChannelEnum.ALLIN_ALI_PAY, OrderPayChannelEnum.ALLIN_QUICK, OrderPayChannelEnum.ALLIN_UNION, OrderPayChannelEnum.ALLIN_BALANCE).collect(Collectors.toList())),

    /**
     * 通联支付 - 微信小程序支付 AppId - 45
     */
    ALLIN_WECHAT_APPLET_APP_ID(45, "通联微信小程序支付AppId", "allin_wechat_applet_app_id", Collections.singletonList(OrderPayChannelEnum.ALLIN_WECHAT)),

    /**
     * 通联支付 - 微信小程序支付 AppKey - 46
     */
    ALLIN_WECHAT_APPLET_APP_KEY(46, "通联微信小程序支付AppKey", "allin_wechat_applet_app_key", Collections.singletonList(OrderPayChannelEnum.ALLIN_WECHAT)),

    /**
     * 通联支付 - 所有支付方式通用 私钥证书密码 - 47
     */
    ALLIN_PRIVATE_CERT_FILE_PSW(47, "通联支付私钥证书秘钥", "allin_private_cert_psw", Stream.of(OrderPayChannelEnum.ALLIN_WECHAT, OrderPayChannelEnum.ALLIN_ALI_PAY, OrderPayChannelEnum.ALLIN_QUICK, OrderPayChannelEnum.ALLIN_UNION, OrderPayChannelEnum.ALLIN_BALANCE).collect(Collectors.toList())),

    /**
     * 通联支付 - 微信收银宝子商户号 - 48
     */
    ALLIN_WECHAT_MERCHANT_ID(48, "微信收银宝子商户号", "allin_wechat_merchant_id", Collections.singletonList(OrderPayChannelEnum.ALLIN_WECHAT)),

    /**
     * 建行支付 - B2B支付 - 商户号
     */
    CCB_B2B_MERCHANT_ID(50, "建行B2B支付商户号", "ccb_b2b_merchant_id", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 分行代码
     */
    CCB_B2B_BRANCH_ID(51, "建行B2B支付分行代码", "ccb_b2b_branch_id", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 商户柜台代码
     */
    CCB_B2B_POS_ID(52, "建行B2B支付商户柜台代码", "ccb_b2b_pos_id", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 柜台公钥
     */
    CCB_B2B_PUBLIC_KEY(53, "建行B2B支付柜台公钥", "ccb_b2b_public_key", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 支付超时时间（小时）
     */
    CCB_B2B_TIME_OUT_HOURS(54, "建行B2B支付超时时间(小时)", "ccb_b2b_time_out_hours", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 支付密码
     */
    CCB_B2B_PASSWORD(55, "建行B2B支付支付密码", "ccb_b2b_password", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 外联平台 - ip地址
     */
    CCB_B2B_IP_ADDRESS(56, "建行B2B支付外联平台ip地址", "ccb_b2b_ip_address", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 外联平台 - 端口
     */
    CCB_B2B_PORT(57, "建行B2B支付外联平台端口", "ccb_b2b_port", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 外联平台 - 操作员号
     */
    CCB_B2B_USER_ID(58, "建行B2B支付外联平台操作员号", "ccb_b2b_userId", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),

    /**
     * 建行支付 - B2B支付 - 外联平台 - 操作员交易密码
     */
    CCB_B2B_USER_PASSWORD(59, "建行B2B支付外联平台操作员交易密码", "ccb_b2b_user_password", Collections.singletonList(OrderPayChannelEnum.CCB_B2B)),


    /**
     * 建行支付 - 数字人民币支付 - 商户号
     */
    CCB_DIGITAL_MERCHANT_ID(60, "建行数字人民币支付商户号", "ccb_digital_merchant_id", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 分行代码
     */
    CCB_DIGITAL_BRANCH_ID(61, "建行数字人民币支付分行代码", "ccb_digital_branch_id", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 商户柜台代码
     */
    CCB_DIGITAL_POS_ID(62, "建行数字人民币支付商户柜台代码", "ccb_digital_pos_id", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 柜台公钥
     */
    CCB_DIGITAL_PUBLIC_KEY(63, "建行数字人民币支付柜台公钥", "ccb_digital_public_key", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 支付超时时间（小时）
     */
    CCB_DIGITAL_TIME_OUT_HOURS(64, "建行数字人民币支付超时时间(小时)", "ccb_digital_time_out_hours", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 商户结算账户
     */
    CCB_DIGITAL_SETTLEMENT_ACCOUNT(65, "建行数字人民币支付商户结算账户", "ccb_digital_settlement_account", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 二级商户号
     */
    CCB_DIGITAL_SUB_MERCHANT_ID(66, "建行数字人民币支付二级商户号", "ccb_digital_sub_merchant_id", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 调用方ID
     */
    CCB_DIGITAL_CORP_ID(67, "建行数字人民币支付瓦片平台调用方ID", "ccb_digital_corpId", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 接口使用场景
     */
    CCB_DIGITAL_SCENARIO(68, "建行数字人民币支付瓦片平台接口使用场景", "ccb_digital_scenario", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 操作员号
     */
    CCB_DIGITAL_USER_ID(69, "建行数字人民币支付瓦片平台操作员号", "ccb_digital_userId", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 操作员交易密码
     */
    CCB_DIGITAL_PASSWORD(70, "建行数字人民币支付瓦片平台操作员交易密码", "ccb_digital_password", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 瓦片公钥1
     */
    CCB_DIGITAL_PUB_KEY_1(71, "建行数字人民币支付瓦片平台瓦片公钥1", "ccb_digital_pub_key_1", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 瓦片公钥2
     */
    CCB_DIGITAL_PUB_KEY_2(72, "建行数字人民币支付瓦片平台瓦片公钥2", "ccb_digital_pub_key_2", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL)),

    /**
     * 建行支付 - 数字人民币支付 - 瓦片平台 - 瓦片私钥1
     */
    CCB_DIGITAL_PRI_KEY_1(73, "建行数字人民币支付瓦片平台瓦片私钥1", "ccb_digital_pri_key_1", Collections.singletonList(OrderPayChannelEnum.CCB_DIGITAL));

    OrderPaymentParameterEnum(Integer code, String name, String key, List<OrderPayChannelEnum> payChannels) {
        this.code = code;
        this.name = name;
        this.key = key;
        this.payChannels = payChannels;
    }

    private Integer code;
    private String name;
    private String key;
    private List<OrderPayChannelEnum> payChannels;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getKey() {
        return key;
    }

    public List<OrderPayChannelEnum> getPayChannels() {
        return payChannels;
    }

    /**
     * 根据枚举值获取Key
     * @param code 枚举值
     * @return Key
     */
    public static String getKeyByCode(Integer code) {
        OrderPaymentParameterEnum paymentParameterEnum = Arrays.stream(OrderPaymentParameterEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return paymentParameterEnum == null ? "未知" : paymentParameterEnum.getKey();
    }

    public static OrderPaymentParameterEnum parse(Integer code) {
        return Arrays.stream(OrderPaymentParameterEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(UNKNOWN);
    }

    public static List<OrderPaymentParameterEnum> findAllInPayParameters() {
        return Stream.of(ALLIN_SYS_ID, ALLIN_PRIVATE_CERT_FILE, ALLIN_PUBLIC_CERT_FILE, ALLIN_STANDARD_SET, ALLIN_DELEGATE_SET, ALLIN_WECHAT_APPLET_APP_ID, ALLIN_WECHAT_APPLET_APP_KEY, ALLIN_PRIVATE_CERT_FILE_PSW).collect(Collectors.toList());
    }
}
